<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://www.zkingsoft.com" prefix="matrix"%>
<%@ page import="com.zkingsoft.constance.SystemConstance"%>
<%@ page import="com.zkingsoft.util.WebUtil"%>
<%
	String isShowHotel = "true";
	String login_plat = String.valueOf(WebUtil.getSessionAttribute(SystemConstance.LOGIN_PLAT));
	if(SystemConstance.PLAT_HOTEL.equals(login_plat)) {
		isShowHotel = "false";
	}

	String isFactoryLogin = "false";
	if(SystemConstance.PLAT_FACTORY.equals(login_plat)) {
		isFactoryLogin = "true";
	}
	
	String isCompanyLogin = "false";
	if(SystemConstance.PLAT_COMPANY.equals(login_plat)) {
		isCompanyLogin = "true";
	}
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<style type="text/css">
.huanhang {
	word-break: break-all;
	word-wrap: break-all;
}

#serchform .input-group {
	margin: 5px 0;
}

#serchform .select2, .select2-selection--single {
	height: 34px !important;
	width: 100% !important;
}

#serchform .input-group-addon {
	font-weight: 700;
	min-width: 100px;
	border-right: 0 !important;
	background: #fbfbfb;
	padding: 0;
	width: 1% !important;
}

#serchform .m-r-10 {
	margin-right: 10px;
}
</style>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<!-- 搜索框部分start -->
		<matrix:btn value="LinOrder:search">
			<div class="row">
				<div class="col-sm-12">
					<form class="form-inline" id="serchform">
						<div class="row">
							<div class="col-sm-3">
								<div class="input-group">
									<span class="input-group-addon">订单编号</span> <input
										placeholder="请输入订单编号" name="orderNum" type="text"
										class="form-control" id="orderNum">
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-group">
									<span class="input-group-addon">订单状态</span> <select
										class="form-control select2" name="orderState" id="orderState">
										<option value="">请选择订单状态</option>
										<option <c:if test="${obj.orderState eq 1}"> selected="selected"</c:if>
											value="1">已创建</option>
										<option <c:if test="${obj.orderState eq 2}"> selected="selected"</c:if>
											value="2">入库运输</option>
										<option <c:if test="${obj.orderState eq 3}"> selected="selected"</c:if>
											value="3">已入库</option>
										<option <c:if test="${obj.orderState eq 4}"> selected="selected"</c:if>
											value="4">已出库</option>
										<option <c:if test="${obj.orderState eq 5}"> selected="selected"</c:if>
											value="5">出库运输</option>
										<option <c:if test="${obj.orderState eq 6}"> selected="selected"</c:if>
											value="6">已验收</option>
									</select>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-sm-3">
			                    <div class="input-group">
			                        <span class="input-group-addon">创建时间</span>
			                        <input type="text" placeholder="请输入起始时间" class="form-control dataInput" id="startTime" name="startTime">
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-group" style="padding-right:100px">
									<input type="text" placeholder="请输入结束时间" class="form-control dataInput" id="endTime" name="endTime">
			                    </div>
			                </div>
							<div class="col-sm-3">
								<div class="input-group" style="top: 3px;">
									<button onclick="myGrid.serchData()" type="button"
										class="btn btn-info btn-sm m-r-10">
										<i class="fa fa-search "></i> 搜索
									</button>
									<button onclick="myReset('#serchform');" type="button"
										class="btn btn-info btn-sm m-r-10">
										<i class="fa fa-refresh "></i> 重置
									</button>
								</div>
							</div>
						</div>
<!-- 						<div class="form-group mr-20"> -->
<!-- 							<label for="hotelName">酒店</label> <select name="hotelId" -->
<!-- 								style="width: 184px;" class="form-control autoFull select2" -->
<%-- 								data-url="${path}/admin/linHotel/showAll" data-value="hotelId" --%>
<!-- 								data-filed="hotelName"> -->
<!-- 								<option value="">请选择酒店</option> -->
<!-- 							</select> -->
<!-- 						</div> -->
<!-- 						<br> -->
<!-- 						<div class="btn-group search-list " style="font-weight: 700"> -->
<!-- 							订单状态</div> -->
<!-- 						<div class="form-group mr-20" style="margin-left: 5px"> -->
<!-- 							<select class="form-control select2" name="orderState" -->
<!-- 								style="width: 184px;"> -->
<!-- 								<option value="">请选择订单状态</option> -->
<%-- 								<option <c:if test="${obj.orderState eq 1}"> selected="selected"</c:if> value="1">已创建</option> --%>
<%-- 								<option <c:if test="${obj.orderState eq 2}"> selected="selected"</c:if> value="2">入库运输</option> --%>
<%-- 								<option <c:if test="${obj.orderState eq 3}"> selected="selected"</c:if> value="3">已入库</option> --%>
<%-- 								<option <c:if test="${obj.orderState eq 4}"> selected="selected"</c:if> value="4">已出库</option> --%>
<%-- 								<option <c:if test="${obj.orderState eq 5}"> selected="selected"</c:if> value="5">出库运输</option> --%>
<%-- 								<option <c:if test="${obj.orderState eq 6}"> selected="selected"</c:if> value="6">已验收</option> --%>
<!-- 							</select> -->
<!-- 						</div> -->
<!-- 						<div class="form-group mr-20"> -->
<!-- 							<label style="margin-left: 11px">创建时间</label> <input type="text" -->
<!-- 								placeholder="请输入起始时间" class="form-control dataInput" -->
<!-- 								id="startTime" name="startTime" -->
<!-- 								style="width: 184px; margin-left: 5px"> <label -->
<!-- 								style="margin-left: 14px; margin-right: 16px">---</label> <input -->
<!-- 								type="text" placeholder="请输入结束时间" -->
<!-- 								class="form-control dataInput" id="endTime" name="endTime" -->
<!-- 								style="width: 184px;"> -->
<!-- 						</div> -->
<!-- 						<button onclick="myGrid.serchData()" type="button" -->
<!-- 							class="btn btn-info btn-sm"> -->
<!-- 							<i class="fa fa-search "></i> 搜索 -->
<!-- 						</button> -->
<!-- 						<button onclick="myReset('#serchform');" type="button" -->
<!-- 							class="btn btn-info btn-sm"> -->
<!-- 							<i class="fa fa-refresh "></i> 重置 -->
<!-- 						</button> -->
					</form>
				</div>
			</div>
		</matrix:btn>
		<!-- 搜索框部分en -->
		<div class="ibox-content radius-5 mt-5 mpanel">
			<div class="row">
				<div class="col-sm-12">
					<div class="option-bar">
<%-- 						<matrix:btn value="LinOrder:dels"> --%>
<!-- 							<button onclick="myGrid.delItems('orderId')" type="button" -->
<!-- 								class="btn btn-danger btn-sm"> -->
<!-- 								<i class="fa fa-trash"></i>批量删除 -->
<!-- 							</button> -->
<%-- 						</matrix:btn> --%>
<%-- 						<matrix:btn value="LinOrder:add"> --%>
<!-- 							<button onclick="openAdd()" type="button" -->
<!-- 								class="btn btn-success btn-sm"> -->
<!-- 								<i class="fa fa-plus"></i> 新增 -->
<!-- 							</button> -->
<%-- 						</matrix:btn> --%>
						<button onclick="DataExport()" type="button" 
						class="btn btn-success btn-sm">
						<i class="fa fa-download"></i> Excel导出</button>
					</div>
					<table id="mgrid">
						<thead>
							<tr>
								<th data-checkbox="true"></th>
								<th data-formatter="MGrid.indexfn" data-align="center"
									data-width="30px" data-field="index">序号</th>
								<th data-field="orderNum">订单编号</th>
								<th data-field="hotelName">酒店名</th>
								<th data-field="orderState" data-formatter="setOrderState">订单状态</th>
								<th data-field="orderTotalNum">总数量</th>
								<th data-field="orderTotalPrice" data-formatter="setOrderPrice">总价格</th>
								<th data-field="orderTotalLoss">总损耗</th>
								<th data-field="orderCreatetime" data-formatter="MGrid.getTime">创建时间</th>
								<th data-field="orderRemark" data-width="30%"
									data-class="huanhang">订单备注</th>
								<th data-align="center" data-width="95px" data-field="orderId"
									data-formatter="buidOperate">操作</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript"
		src="${path }/resource/js/systools/MJsBase.js"></script>
	<script type="text/javascript">
	function setOrderState(value, row, index) {
		switch(value) {
		case "<%=SystemConstance.ORDER_STATE_CREATE%>" : return "已创建";break;
		case "<%=SystemConstance.ORDER_STATE_TRANSPORT1%>" : return "入库运输";break;
		case "<%=SystemConstance.ORDER_STATE_STORAGE%>" : return "已入库";break;
		case "<%=SystemConstance.ORDER_STATE_OUT%>" : return "已出库";break;
		case "<%=SystemConstance.ORDER_STATE_TRANSPORT2%>" : return "出库运输";break;
		case "<%=SystemConstance.ORDER_STATE_INSPECTED%>": return "已验收";break;
		default: return "";
		}
	}
	function setOrderPrice(value, row, index) {
		if("<%=isFactoryLogin%>" == 'true') {
			return value ? value : 0;
		} else if("<%=isCompanyLogin%>" == 'true'){
			if('${orderType}' == 'factory') {
				return value ? value : 0;
			} else {
				return row.orderRealPrice ? row.orderRealPrice : 0;
			}
		} else {
			return row.orderRealPrice ? row.orderRealPrice : 0;
		}
	}
	</script>
	<script type="text/javascript">
		$(".select2").select2();
		MTools.autoFullSelect();
		
		var myGrid;
		
		$(function() {
			var delUrl = "";
			<matrix:btn value="LinOrder:del">
			delUrl = "${path}/admin/linOrder/del";
			</matrix:btn>
			myGrid = MGrid.initGrid({
				url : "${path}/admin/linOrder/showList?month=${month}&hotelId=${hotelId}",
				delUrl : delUrl,
				onClickCell : function(field, value, row, $element) {
					if (field && field != "orderId") {
						layer.open({
							type : 2,
							title : "查看订单" + row.orderNum,
							area : [ MUI.SIZE_L, '400px' ],
							maxmin : true,
							content : [ '${path}/admin/linOrder/getDetail?id=' + row.orderId + '&orderType=${orderType}' ]
						});
					}
				},
			});
			//时间
			MTools.ininDatetimepicker({timeSelecter : '.dataInput'});
			//限制结束时间不小于开始时间
			MTools.limitStartEndTime({
				beginTimeId : "#startTime",
				endTimeId : "#endTime"
			});
		});

		function buidOperate(value, row, index) {
			var html = [];
			<matrix:btn value="LinOrder:search">
			html[0] = '<a  onClick="openFlows(\'' + value + '\',\'' + row.orderNum + '\')"  title="查看流水" class="fa fa-search option"></a>'
			</matrix:btn>
// 			<matrix:btn value="LinOrder:edit">
// 			html[1] = '<a  onClick="openEdit(\'' + value + '\',\'' + row.orderNum + '\')"  title="编辑" class="fa fa-edit option"></a>'
// 			</matrix:btn>
// 			<matrix:btn value="LinOrder:del">
// 			html[2] = '<a onClick="myGrid.delItem(' + value + ')" title="删除" class="fa fa-close option text-danger"></a>';
// 			</matrix:btn>
			return html.join("");
		}
		//打开添加界面
		<matrix:btn value="LinOrder:add">
		function openAdd() {
			layer.full(layer.open({
				type : 2,
				title : "添加订单",
				area : [ MUI.SIZE_L, '400px' ],
				maxmin : true,
				content : [ '${path}/admin/linOrder/editForm' ]
			}));
		}
		</matrix:btn>

		//打开编辑界面
		<matrix:btn value="LinOrder:edit">
		function openEdit(id, orderNum) {
			layer.open({
				type : 2,
				title : "修改订单" + orderNum,
				area : [ MUI.SIZE_L, '400px' ],
				maxmin : true,
				content : [ '${path}/admin/linOrder/editForm?id=' + id ]
			});
		}
		</matrix:btn>

		<matrix:btn value="LinOrder:search">
		//打开流水记录
		function openFlows(id, orderNum) {
			layer.open({
				type : 2,
				title : "查看流水" + orderNum,
				area : [ MUI.SIZE_L, '400px' ],
				maxmin : true,
				content : [ '${path}/admin/linOrder/getLogList?orderId=' + id ]
			});
		}
		</matrix:btn>
		function timeFormat(value, row, index) {
			var d = new Date(value);
			return d.getFullYear() + "-" + (d.getMonth() + 1) + "-"
					+ d.getDate() + " " + d.getHours() + ":" + d.getMinutes()
					+ ":" + d.getSeconds();
		}
		
		function myReset(formId) {
			$(':input', formId).not(':button, :submit, :reset, :hidden')
					.val('').removeAttr('value').removeAttr('checked')
					.removeAttr('selected');
			$(".select2", formId).val("").trigger("change");
			
			//时间
			MTools.ininDatetimepicker({timeSelecter : '.dataInput'});
			//限制结束时间不小于开始时间
			MTools.limitStartEndTime({
				beginTimeId : "#startTime",
				endTimeId : "#endTime"
			});
		}
		
		//Excel导出
		function DataExport(){  
// 			var orderNum = $("#orderNum").val();
// 			var orderState = $("#orderState").val();
// 			var startTime = $("#startTime").val();
// 			var endTime = $("#endTime").val();
			
			var form = $('#serchform');
			$('#serchform')[0].action="${path}/admin/linOrder/exporOrderDetail?month=${month}&hotelId=${hotelId}&orderType=${orderType}";
			$('#serchform')[0].method="POST";
			$('#serchform').submit();
			
// 			window.location.href="${path}/admin/linOrder/exporOrderDetail?orderNum="+orderNum+"&orderState="+orderState+"&startTime="+startTime+"&endTime="+endTime;
        };
		
	</script>
</body>
</html>
